<?php
#####################################################################################
//A 数组   B  表单   D 数据库  E 正则   F 文件相关  J 常用检测  S str   T 模版  M  时间相关
#####################################################################################



/**function Ab($op1, $op2)a_comp
 * 返回数组元素的个数
 * $var array
 * retrun the key if str in array
 */
function Ab($op1, $op2){
    if (count($op1) < count($op2)) {
        return -1; // $op1 < $op2
    } elseif (count($op1) > count($op2)) {
        return 1; // $op1 > $op2
    }
    foreach ($op1 as $key => $val) {
        if (!array_key_exists($key, $op2)) {//检查给定的键名或索引是否存在于数组中
            return null; // uncomparable
        } elseif ($val < $op2[$key]) {
            return -1;
        } elseif ($val > $op2[$key]) {
            return 1;
        }
    }
    return 0; // $op1 == $op2
}

/***function Ac($var,$m) A count
 * 返回数组元素的个数
 * $var array
 * retrun the key if str in array
 */
function Ac($var){
	if(is_array($var))
		{
		$num=count($var);
		}
		else
		{
		$num=0;
		}
		return $num;
	}

/**function Ef($var,$m) getarraykey;
 * $var str 要在数组中查找的字符号
 * $m array
 *
 */
function Af($var,$m){
	if (stristr($var,$m)){
		return true;
	}else{
		return false;
	}
	exit;
}


/**function Eak($var,$m) getarraykey;
 * $var str 要在数组中查找的字符号
 * $m array
 * retrun the key if str in array
 */
function Afk($var,$m){
foreach($m as $key =>$value)
	 {
		if (eregi($var,$value))
		{
		return $key;
		exit;
		}
	}
}

/**array_unique;array 返回不在 $xian 里出现的新数组
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  array 返回不在 $xian 里出现的新数组
 */
function Au($ar,$xian=0){
	$ar= array_unique($ar);
		switch($xian){
			case 0:{
				return $ar;
			}
			case 1:{
				$var1=array();
				foreach($ar as $valar){
					if($valar!=''){
						$var1[]=$valar;
					}
				}
				return $var1;

			}

			default :{
				$var1=array();
			foreach($ar as $valar){
					if(!in_array($valar,$xian)){
						$var1[]=$valar;
					}

				}
				return $var1;

			}
		}

}

/** Bcr bao crate radio//创建多选按钮组$name:按钮name的值,$dvalue默认单选按钮的值,$style样式,$js为js样式$value单选按钮值数组
 *
 *
 *
 */
function Bcc($name,$yvalue,$xvalue,$dvalue,$fxian,$fparam,$css,$js=''){
$i=0;
 $num=count($yvalue);
	foreach($yvalue as $temp)
	{
		 if(in_array($temp,$dvalue))
		 {
		$str.=" <input name=\"".$name."\" id=\"".$name.$i."\" type=\"checkbox\" value=\"".$temp."\" checked=\"checked\" ".$fparam." ".$css."  ".$js." /> <label for=\"".$name.$i."\" style='cursor:hand;'>".$xvalue[$temp]."<label>";
		 }
		 else
		 {
		$str.="<input name=\"".$name."\" id=\"".$name.$i."\" type=\"checkbox\" value=\"".$temp."\"  ".$fparam."  ".$css."  ".$js." /> <label for=\"".$name.$i."\" style='cursor:hand;'>".$xvalue[$temp]."</label>";
		 }
		 $i++;
	}
	return $str.$fxian;
}

/** Bcr bao crate radio//创建单选按钮$name:按钮name的值,$dvalue默认单选按钮的值,$style样式,$js为js样式$value单选按钮值数组
 *
 *
 */
function Bcr($name,$yvalue,$xvalue,$dvalue,$ydefault='',$xdefault='',$fxian,$fparam,$css,$js=''){
	$i=1;
    $lg=$_GET['lg']==''?'zh':$_GET['lg'];
    if($xdefault!=''){
        if($_GET[$lg][str_replace(array($lg,'[',']'),'',$name)]==''){
            $checked=' checked="checked" ';
        }
		$str.="<input name=\"".$name."\" class=\"sex\" type=\"radio\" value=\"".$temp."\" {$checked} ".$fparam." ".$css."  ".$js." />".$xdefault."";
    }
	foreach($yvalue as $temp)
	{
		 if($temp==$dvalue)
		 {
             if($xdefault!='' && $_GET[$lg][str_replace(array($lg,'[',']'),'',$name)]==''){
                $str.="<input name=\"".$name."\" class=\"sex\" type=\"radio\" value=\"".$temp."\" ".$fparam." ".$css."  ".$js." />".$xvalue[$temp]."";
             }else{
                $str.="<input name=\"".$name."\" class=\"sex\" type=\"radio\" value=\"".$temp."\" checked=\"checked\" ".$fparam." ".$css."  ".$js." />".$xvalue[$temp]."";
             }
		 }
		 else
		 {
		$str.="<input name=\"".$name."\" class=\"sex\" type=\"radio\" value=\"".$temp."\"   ".$fparam." ".$css."  ".$js."  />".$xvalue[$temp]."";
		 }
		 $i++;
	}
	return $str;
}

/** Bcs bao crate radio//创建下拉列表$name:按钮name的值,$dvalue默认单选按钮的值,$style样式,$js为js样式$value单选按钮值数组
 *
 *
 *
 */
function Bcs($name,$yvalue,$xvalue,$dvalue,$ydefault='',$xdefault='',$fxian,$fparam,$css,$js='',$search=''){
    $i=0;
    $lg=$_GET['lg']==''?'zh':$_GET['lg'];

    /**
     * 多城市模块过滤
     */
    if(defined('MULTI_CITY') && MULTI_CITY && $name==$lg.'[city]' && $_SESSION['userinfo']['user']!='admin'){
        //$dvalue=get_user_city();
        //$readonly='disabled="true"';
    }
    if(is_array($dvalue)){
        $str.="<select {$readonly} name=\"".$name."\"  ".$fparam."  ".$css."   ".$js.">";
        if($xdefault !='' && $search=='')
        {
            $str.="<option value=\"".$ydefault."\"   >".$xdefault."</option>";

        }
        foreach($yvalue as $temp)
        {

             if(in_array($temp,$dvalue))
             {
                if($xdefault!='' && $_GET[$lg][str_replace(array($lg,'[',']'),'',$name)]=='' && $search!=''){
                    $str.="<option value=\"".$temp."\" >".$xvalue[$temp]."</option>";
                }else{
                    $str.="<option value=\"".$temp."\"  selected=\"selected\" >".$xvalue[$temp]."</option>";
                }
             }
             else
             {
            $str.="<option value=\"".$temp."\"   >".$xvalue[$temp]."</option>";
             }
             $i++;
        }
         $str.="</select>";

    }else{
        $str.="<select {$readonly} name=\"".$name."\"  ".$fparam."  ".$css."   ".$js." >";
        if($xdefault !='')
        {
            $str.="<option value=\"".$ydefault."\"   >".$xdefault."</option>";
        }
        foreach($yvalue as $temp)
        {

             if($temp==$dvalue)
             {
                if($xdefault!='' && $_GET[$lg][str_replace(array($lg,'[',']'),'',$name)]=='' && $search!=''){
                    $str.="<option value=\"".$temp."\" >".$xvalue[$temp]."</option>";
                }else{
                    $str.="<option value=\"".$temp."\"  selected=\"selected\" >".$xvalue[$temp]."</option>";
                }
             }
            else
            {
                $str.="<option value=\"".$temp."\"   >".$xvalue[$temp]."</option>";
            }
            $i++;
        }
        $str.="</select>";

    }
	$str.=$fxian;
	return $str;
}

/**
 * 全角符号转为半角符号
 *
 * @param String $sign
 * @return String
 */
function change_sign($sign){
	$sign = str_replace(array('‘','’'),array("'","'"),str_replace(array('“','”'),array('"','"'),$sign));
	return $sign;
}

/** 创建DEFAULTTYPE属性
 *
 *
 *
 */
function DEFAULTTYPE($zd,$lang,$nowvalue,$g,$change=''){
	$g['structure'][$zd]['DEFAULT']=change_sign($g['structure'][$zd]['DEFAULT']);
	if($nowvalue!=''){//Ja($nowvalue);
		if($change!=''){
			switch($change){
				case 'date':
					return date("Y-m-d",$nowvalue);
					break;
				case 'datetime':
					return date("Y-m-d H:i:s",$nowvalue);
					break;
				case 'my97':
					return date($g['structure'][$zd]['phpformat'],$nowvalue);
					break;
			}
		}else{
			return $nowvalue;
		}
	}else{
		switch ($g['structure'][$zd]['DEFAULTTYPE']){
			case 'C':{
				return $g['structure'][$zd]['DEFAULT'];
				break;
			}
			case 'S':{
						$temp=explode("#",$g['structure'][$zd]['DEFAULT']);
						$num=Ac($temp);
						if($num=='1'){
						return $_SESSION[$temp[0]];
						}else{
						return $_SESSION[$temp[0]][$temp[1]];
						}

				break;
			}
			case 'G':{	global ${$g['structure'][$zd]['DEFAULT']};
						return ${$g['structure'][$zd]['DEFAULT']};
				break;
			}
			case 'V':{	global ${$g['structure'][$zd]['DEFAULT']};
						return ${$g['structure'][$zd]['DEFAULT']};
				break;
			}
			case 'F':{
						return $g['structure'][$zd]['DEFAULT']();
				break;
			}
			case 'E':{
						eval("\$tmp = {$g['structure'][$zd]['DEFAULT']};");
						return $tmp;
				break;
			}
			case 'R':{
			return $_GET[$g['structure'][$zd]['DEFAULT']];
				break;
			}
			default : {
				return '';
				break;
			}
		}
	}
}
/** 创建text属性
 *
 *
 *
 */
function text($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg',$change=''){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	 $bb="<input name=\"".$lang."[".$zd."]\" type=\"text\" id=\"".$lang."[".$zd."]\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp,$change)."\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."    ".$temp['structure'][$zd]['js']."   >".(($temp['structure'][$zd]['fxian'])?("<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />"):(""))."";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建text属性
 *
 *
 *
 */
function bind($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){

	if($fh==0){
			$bt=$nowvalue['COMMENT'];
	if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	 $bb="<input name=\"".$lang."[bdb]\" type=\"text\"  id=\"".$lang."[bdb]\"   value=\"".$nowvalue['bdb']."\"  readonly >
	 <input name=\"".$lang."[bdid]\" type=\"text\"  id=\"".$lang."[bdid]\"   value=\"".$nowvalue['bdid']."\"  readonly   >";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}

/** 创建MD5验证加密字段
 *
 *
 *
 */
function md5str($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){
	 $bb="
	 <input name=\"".$lang."[".$zd."]\" type=\"password\"  id=\"".$lang."[".$zd."]\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."\"      ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."    ".$temp['structure'][$zd]['js']."   >
	 <label></label><div id=\"passwordInfo\"></div>";
	//Jc($temp['structure']);
	 if($temp['structure'][$zd]['yan']==1){
	 $bb.="重新确认".$temp['structure'][$zd]['COMMENT']."：&nbsp;<input name=\"".$lang."1\" type=\"password\"  id=\"".$lang."1\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."\"  ><ui:v for=\"".$lang."1\"    rule=\"compare\" toElement=\"".$lang."[".$zd."]\" as=\"String\"  empty=\"请确认您的".$temp['structure'][$zd]['COMMENT']."\" warn=\"两次输入的".$temp['structure'][$zd]['COMMENT']."不一致\" tips=\"请重复输入一次您的".$temp['structure'][$zd]['COMMENT']."\" pass=\"验证正确了\" />";
	 }
		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建hide属性
 *
 *
 *
 */
function hide($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	 $bb="<input name=\"".$lang."[".$zd."]\" type=\"hidden\" id=\"".$lang."[".$zd."]\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."    ".$temp['structure'][$zd]['js']."   >";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 权限判断CURD
 *
 *
 *
 */
function menuright($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	 $bb="<input name=\"".$lang."[".$zd."]\" type=\"text\" id=\"".$lang."[".$zd."]\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."    ".$temp['structure'][$zd]['js']."   >";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}

/** 权限判断CURD
 *
 *
 *
 */
function menu($lang='zh',$method=1,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
//S
if($_SESSION['userinfo']['right']=='S'){
	return '1';
}else{
	switch ($temp['rcfg']){

		case "M":{

			break;
		}
		case "Z":{

			break;
		}
		case "L":{

			break;
		}
	}

}
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	 $bb="<input name=\"".$lang."[".$zd."]\" type=\"text\" id=\"".$lang."[".$zd."]\"   value=\"".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."    ".$temp['structure'][$zd]['js']."   >";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建引入文件属性
 *
 *
 *
 */
function phpfile($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

				$finfo=file(BIC_ROOT."admin/db/".$lang.$nowvalue.".php");

				$finfo=implode('',$finfo);
	$bb="<textarea name=\"".$lang."[".$zd."]\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."   ".$temp['structure'][$zd]['js']."   id=\"".$lang."[".$zd."]\"  >".$finfo."</textarea>".(($temp['structure'][$zd]['fxian'])?("<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />"):(""))."";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}/** 创建文本区域
 *
 *
 *
 */
function textarea($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){

	$bb="<textarea name=\"".$lang."[".$zd."]\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."   ".$temp['structure'][$zd]['js']."   id=\"".$lang."[".$zd."]\"  >".DEFAULTTYPE($zd,$lang,$nowvalue,$temp)."</textarea>".(($temp['structure'][$zd]['fxian'])?("<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />"):(""))."";

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建文件上传域
 *
 *
 * 2009-3-6 增加了图像path的功能,默认还是为/uploads/pic/
 */
function fileup($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){
				$dfvalue=explode(',',$nowvalue);
				foreach($dfvalue as $tttemp){
				$num=substr($tttemp,-5,1);
				//Ja($num);
				$otype=substr($tttemp,-3);
				$path=$temp['structure'][$zd]['path']==''?'/uploads/pic/':$temp['structure'][$zd]['path'];
				switch($otype){
					case 'jpg':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" rel='lytebox' target=_blank><img src='".$path.$tttemp."' alg='点击查看原图' title='点击查看原图' style='margin-left:50px;width:50px;height:50px;border:0;' border='0' ></a>";	break;
					}
					case 'gif':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" rel='lytebox' target=_blank><img width=68px  src='".$path.$tttemp."' alg='点击查看原图' title='点击查看原图' style='margin-left:50px;width:50px;height:50px;border:0;' border='0' ></a>";	break;
					}
					case 'png':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" rel='lytebox' target=_blank><img src='".$path.$tttemp."' alg='点击查看原图' title='点击查看原图' style='margin-left:50px;width:50px;height:50px;border:0;' border='0' ></a>";	break;
					}
					case 'bmp':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" rel='lytebox' target=_blank><img src='".$path.$tttemp."' alg='点击查看原图' title='点击查看原图' style='margin-left:50px;width:50px;height:50px;border:0;' border='0' ></a>";	break;
					}
					case 'txt':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" target=_blank><img src='/admin/img/archive.png' border='0' ></a>";	break;
					}
					case 'txt':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" target=_blank><img src='/admin/img/archive.png'  border='0' ></a>";	break;
					}
					case 'rar':
					case 'zip':{
						$ddvalue[$num]="<a href=\"".$path.$tttemp."\" target=_blank><img src='/admin/img/archive.png' alg='点击下载源文件' title='点击下载源文件' style='margin-left:50px;border:0;' border='0' ></a>";	break;
					}
				}

				}
				$format=implode(',',$temp['structure'][$zd]['format']);
				for($num=1;$num<=$temp['structure'][$zd]['filenum'];$num++){
			$bb.=" <input type=\"file\" name=\"".$lang."[".$zd."][".$num."]\" id=\"".$lang."[".$zd."][".$num."]\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."   ".$temp['structure'][$zd]['js']."  />".(($ddvalue[$num])?($ddvalue[$num]):((($temp['structure'][$zd]['fxian'])?("<ui:v for=\"".$lang."[".$zd."][".$num."]\" require=\"true\" rule=\"filter\"  ".$temp['structure'][$zd]['fxian']."   tips=\"请选择【".$format."】格式的文件\"  as=\"file\" accept=\"".$format."\"/>"):(""))))."<br>";
				}


		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
function filebbb($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){
				$dfvalue=explode(',',$nowvalue);
				foreach($dfvalue as $tttemp){
				$num=substr($tttemp,-5,1);
				//Ja($num);
				$otype=substr($tttemp,-3);
				switch($otype){
					case 'jpg':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img src='/uploads/pic/".$tttemp."' border='0' ></a>";	break;
					}
					case 'gif':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img width=68px  src='/uploads/pic/".$tttemp."' border='0' ></a>";	break;
					}
					case 'png':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img src='/uploads/pic/".$tttemp."' border='0' ></a>";	break;
					}
					case 'bmp':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img src='/uploads/pic/".$tttemp."' border='0' ></a>";	break;
					}
					case 'txt':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img src='/admin/img/archive.png' border='0' ></a>";	break;
					}
					case 'txt':{
						$ddvalue[$num]="<a href=\"/uploads/pic/".$tttemp."\" target=_blank><img src='/admin/img/archive.png'  border='0' ></a>";	break;
					}
				}

				}
				$format=implode(',',$temp['structure'][$zd]['format']);
				for($num=1;$num<=$temp['structure'][$zd]['filenum'];$num++){
			$bb.=" <input type=\"file\" name=\"".$lang."[".$zd."][".$num."]\" id=\"".$lang."[".$zd."][".$num."]\"  ".$temp['structure'][$zd]['fparam']."   ".$temp['structure'][$zd]['css']."   ".$temp['structure'][$zd]['js']."  />".(($ddvalue[$num])?($ddvalue[$num]):((($temp['structure'][$zd]['fxian'])?("<ui:v for=\"".$lang."[".$zd."][".$num."]\" require=\"true\" rule=\"filter\"  ".$temp['structure'][$zd]['fxian']."   tips=\"请选择【".$format."】格式的文件\"  as=\"file\" accept=\"".$format."\"/>"):(""))))."<br>";
				}


		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建文本区域
 *
 *
 *
 */
function ubb($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg',$lujing="../../"){
global $$g;
$temp=$$g;
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}
	if($fh==1){


		$dvalue=DEFAULTTYPE($zd,$lang,$nowvalue,$temp);

	Jubb($lang."[".$zd."]",$dvalue,$lujing);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}

}
/** 创建表单下拉列表
 *
 *
 *
 */
function select($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
                $bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
                $bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
        if($temp['structure'][$zd]['method']['table']!=''){

        $tdate=Dgs($temp['structure'][$zd]['method']['table'],$temp['structure'][$zd]['method']['condition']);

            foreach($tdate as $value){
                $yvalue[]=$value[$temp['structure'][$zd]['method']['yvalue']];
                $xvalue[$value[$temp['structure'][$zd]['method']['yvalue']]]=$value[$temp['structure'][$zd]['method']['xvalue']];
            }
        }else{
            $yvalue=$temp['structure'][$zd]['method']['yvalue'];
            $xvalue=$temp['structure'][$zd]['method']['xvalue'];
        }
        //Ja($nowvalue);
        if($nowvalue!=''){
            $temp['structure'][$zd]['method']['dvalue']=$nowvalue;
        }
        if($temp['structure'][$zd]['fxian']){
            $xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
        }

        $bb=Bcs($lang."[".$zd."]",$yvalue,$xvalue,$temp['structure'][$zd]['method']['dvalue'],$temp['structure'][$zd]['method']['ydefault'],$temp['structure'][$zd]['method']['xdefault'],$xian,$temp['structure'][$zd]['fparam'],$temp['structure'][$zd]['css'],$temp['structure'][$zd]['js']);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
function select_for_search($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
                $bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
                $bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
        if($temp['structure'][$zd]['method']['table']!=''){

        $tdate=Dgs($temp['structure'][$zd]['method']['table'],$temp['structure'][$zd]['method']['condition']);

            foreach($tdate as $value){
                $yvalue[]=$value[$temp['structure'][$zd]['method']['yvalue']];
                $xvalue[$value[$temp['structure'][$zd]['method']['yvalue']]]=$value[$temp['structure'][$zd]['method']['xvalue']];
            }
        }else{
            $yvalue=$temp['structure'][$zd]['method']['yvalue'];
            $xvalue=$temp['structure'][$zd]['method']['xvalue'];
        }
        //Ja($nowvalue);
        if($nowvalue!=''){
            $temp['structure'][$zd]['method']['dvalue']=$nowvalue;
        }
        if($temp['structure'][$zd]['fxian']){
            $xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
        }

        $bb=Bcs($lang."[".$zd."]",$yvalue,$xvalue,$temp['structure'][$zd]['method']['dvalue'],'','所有',$xian,$temp['structure'][$zd]['fparam'],$temp['structure'][$zd]['css'],$temp['structure'][$zd]['js'],$temp['structure'][$zd]['search']);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}

function fal(){
 $numargs = func_num_args();
     echo "Number of arguments: $numargs<br />\n";
    for($i=0;$i<$numargs ;$i++) {
         echo ($i+1)." argument is: " . func_get_arg($i) . "<br />\n";
     }

}
//搜索下拉列表
$drop_down_info='';
function drop_down($id,$i,$selected,$table,$lang,$mid,$minfo)
{
global $db,$drop_down_info;
//fal($id,$i,$selected,$table,$mid,$minfo);
$temp=Dgs($table," parentid='".$id."' and lg like '".$lang."'  and del != '1'");
	if($temp !='')
	{
		foreach($temp as $p)
		{	if(in_array($p['id'],$selected)||$p['id']==$selected)
			{
		    $drop_down_info.="<option value=\"".$p['id']."\" selected=\"selected\">".str_repeat('--',$i).$p['title']."</option>";
			}
			else
			{

		    $drop_down_info.="<option value=\"".$p['id']."\">".str_repeat('－',$i).$p['title']."</option>";
			}
			$qq=Dgs($table," parentid='".$p['id']."'  and lg like '".$lang."'  and del != '1'");
			if($qq!='')
			{$j=$i+1;
			drop_down($p[id],$j,$selected,$table,$lang);
			}
		}
		if($mid!==''&&$minfo!='')
		{
		$drop_down_info="<option value=\"".$mid."\">".$minfo."</option>".$drop_down_info;
	    }
	}
else
{
		if($mid!=''&&$minfo!='')
		{
		$drop_down_info="<option value=\"".$mid."\">".$minfo."</option>".$drop_down_info;
	    }
}
}
/** 创建无限级下拉列表
 *
 *
 *
 */
function dselect($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
global $drop_down_info;

$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
if($nowvalue==''){
$nowvalue=$temp['structure'][$zd]['method']['ydefault'];
}
if($temp['structure'][$zd]['fxian']){
$xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
}
//drop_down("-1",0,"-1",'mod',"-1",'根分类');
$drop_down_info='';
//Ja($nowvalue);
drop_down($temp['structure'][$zd]['method']['ydefault'],0,$nowvalue,$temp['name'],$lang,$temp['structure'][$zd]['method']['ydefault'],$temp['structure'][$zd]['method']['xdefault']);
$bb="<select name='".$lang."[".$zd."]' ".$temp['structure'][$zd]['fparam']." ".$temp['structure'][$zd]['css']." ".$temp['structure'][$zd]['js']." >".$drop_down_info."</select> ".$xian;

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
/** 创建表单下拉列表
 *
 *
 *
 */
function checkbox($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
				if($temp['structure'][$zd]['method']['table']!=''){

					$tdate=Dgs($temp['structure'][$zd]['method']['table'],$temp['structure'][$zd]['method']['condition']);

					foreach($tdate as $value){
						$yvalue[]=$value[$temp['structure'][$zd]['method']['yvalue']];
						$xvalue[$value[$temp['structure'][$zd]['method']['yvalue']]]=$value[$temp['structure'][$zd]['method']['xvalue']];
					}
				}else{
					$yvalue=$temp['structure'][$zd]['method']['yvalue'];
					$xvalue=$temp['structure'][$zd]['method']['xvalue'];
				}

		//Ja($nowvalue);
		if($nowvalue!=''){
		$temp['structure'][$zd]['method']['dvalue']=$nowvalue;
		}
		if($temp['structure'][$zd]['fxian']){
		$xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
		}

		$bb=Bcc($lang."[".$zd."][]",$yvalue,$xvalue,$temp['structure'][$zd]['method']['dvalue'],$xian,$temp['structure'][$zd]['fparam'],$temp['structure'][$zd]['css'],$temp['structure'][$zd]['js']);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}

/**
 * 字符串是否在一个以逗号分开的字符串中
 * @param string $current	字符串
 * @param string $haystack	以逗号分开的字符串
 * @return mixed 存在返回：true 不存在：false
 * @author Zuolong Wang 2010-6-8
 */
function in_comma_string($current,$haystack){
    $h = explode(',',$haystack);
    return in_array($current,$h)?true:false;
}

/**
 * 创建无限级多选
 * @param string $zd	表对应的字段
 * @param string $lang	语言
 * @param int $fh		0:返回标题-COMMENT; 1:返回动态内容;
 * @param int $method	0:输出标题或内容； 2:返回标题或内容
 * @param string $nowvalue	默认值
 * @param string $g		数据内容变量名
 * @author Zuolong Wang 2010-6-8 添加/修改
 */
function dcheckbox($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
    global $$g;
    global $drop_down_info;

    $temp=$$g;
    $temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
    $temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
    $temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
    
    /** 输出标题[COMMENT] */
    if($fh==0){
        if(is_array($temp['structure'][$zd]['COMMENT'])){
            $bt=$temp['structure'][$zd]['COMMENT'][$lang];
        }else{
            $bt=$temp['structure'][$zd]['COMMENT'];
        }
        if($method==0){
            echo $bt;
        }
        if($method==1){
            return $bt;
        }
    }

    /** 详细内容 */
    if($fh==1){
        if($nowvalue==''){
            $nowvalue=$temp['structure'][$zd]['method']['ydefault'];
        }
        if($temp['structure'][$zd]['fxian']){
            $xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
        }
        
        //转换变量
        $table = $temp['structure'][$zd]['method']['table'];
        $condition = $temp['structure'][$zd]['method']['condition'];
        $title = $temp['structure'][$zd]['method']['xvalue']!=''?$temp['structure'][$zd]['method']['xvalue']:'title';
        $value = $temp['structure'][$zd]['method']['yvalue']!=''?$temp['structure'][$zd]['method']['yvalue']:'id';
        $js = $temp['structure'][$zd]['js'];
        $css = $temp['structure'][$zd]['css'];
        $current_value = explode(',',$nowvalue);
        
        //详细动态内容
        $checkboxs = Dgs($table,$condition);
        ob_start();
        foreach ($checkboxs as $c_b_k => $c_b_v){
            $checked = in_array($c_b_v[$value],$current_value)?'checked':'';
            echo <<<CHECKBOX
            <input id="d_s_{$c_b_k}" name="{$lang}[{$zd}][]" type="checkbox" {$checked} value="{$c_b_v[$value]}"/>
            <label for="d_s_{$c_b_k}">{$c_b_v[$title]}</label>&nbsp;&nbsp;
CHECKBOX;
        }
        $checkbox = ob_get_clean();
        
        if($method==0){
            echo $checkbox;
        }
        if($method==1){
            return $checkbox;
        }
    }
}

function radio($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
				if($temp['structure'][$zd]['method']['table']!=''){

					$tdate=Dgs($temp['structure'][$zd]['method']['table'],$temp['structure'][$zd]['method']['condition']);

					foreach($tdate as $value){
						$yvalue[]=$value[$temp['structure'][$zd]['method']['yvalue']];
						$xvalue[]=$value[$temp['structure'][$zd]['method']['xvalue']];
					}
				}else{
					$yvalue=array_keys($temp['structure'][$zd]['method']['xvalue']);
					$xvalue=$temp['structure'][$zd]['method']['xvalue'];
				}
				//Jc($yvalue);
				//Jc($xvalue);
	//Ja($nowvalue);
	if($nowvalue!=''){
	$temp['structure'][$zd]['method']['dvalue']=$nowvalue;
	}
	if($temp['structure'][$zd]['fxian']){
	$xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
	}

	$bb=Bcr($lang."[".$zd."]",$yvalue,$xvalue,$temp['structure'][$zd]['method']['dvalue'],$xian,$temp['structure'][$zd]['fparam'],$temp['structure'][$zd]['css'],$temp['structure'][$zd]['js']);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
function radio_for_search($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
$temp['structure'][$zd]['css']=change_sign($temp['structure'][$zd]['css']);
$temp['structure'][$zd]['js']=change_sign($temp['structure'][$zd]['js']);
$temp['structure'][$zd]['fparam']=change_sign($temp['structure'][$zd]['fparam']);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
				if($temp['structure'][$zd]['method']['table']!=''){

					$tdate=Dgs($temp['structure'][$zd]['method']['table'],$temp['structure'][$zd]['method']['condition']);

					foreach($tdate as $value){
						$yvalue[]=$value[$temp['structure'][$zd]['method']['yvalue']];
						$xvalue[]=$value[$temp['structure'][$zd]['method']['xvalue']];
					}
				}else{
					$yvalue=array_keys($temp['structure'][$zd]['method']['xvalue']);
					$xvalue=$temp['structure'][$zd]['method']['xvalue'];
				}
				//Jc($yvalue);
				//Jc($xvalue);
	//Ja($nowvalue);
	if($nowvalue!=''){
	$temp['structure'][$zd]['method']['dvalue']=$nowvalue;
	}
	if($temp['structure'][$zd]['fxian']){
	$xian="<ui:v for=\"".$lang."[".$zd."]\"     ".$temp['structure'][$zd]['fxian']." />";
	}

	$bb=Bcr($lang."[".$zd."]",$yvalue,$xvalue,$temp['structure'][$zd]['method']['dvalue'],'','全部',$temp['structure'][$zd]['css'],$temp['structure'][$zd]['js']);

		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}
function ssx($zd,$lang='zh',$fh=1,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
//Ja($temp);
	if($fh==0){
			if(is_array($temp['structure'][$zd]['COMMENT'])){
			$bt=$temp['structure'][$zd]['COMMENT'][$lang];
			}else{
			$bt=$temp['structure'][$zd]['COMMENT'];
			}
		if($method==0){
			echo $bt;
		}
		if($method==1){
			return $bt;
		}
	}

	if($fh==1){
				//Ja($temp['structure'][$zd]['num']);
				for($i=1;$i<=$temp['structure'][$zd]['num'];$i++){
					if(($nowvalue[$i]==''||$nowvalue[$i]==0)&&$i!=3){
					$nowvalue[$i]=$temp['structure'][$zd]['default'][$i];
					}
					$tezd=Dga($temp['structure'][$zd]['table'],"del!=1 and id ='".$nowvalue[$i]."'");
					$tpzd=Dgs($temp['structure'][$zd]['table'],"del!=1 and parentid ='".$tezd['parentid']."'");
						$yvalue=array();
						$xvalue=array();
						foreach($tpzd as $tpvalue){
							$yvalue[]=$tpvalue['id'];
							$xvalue[]=$tpvalue['title'];
						}

					$param="  style=\"width:auto !@important;border:1px solid #ccc;\" onchange=\"xajax_updatetag(this.value,'".$zd."','".$i."','".$temp['structure'][$zd]['num']."','".$lang."')\"";

				$bb.="<span id='".$zd."".$i."'>".Bcs($lang."[".$temp['structure'][$zd]['zd'][$i]."]",$yvalue,$xvalue,$nowvalue[$i],$ydefault='0',$temp['structure'][$zd]['defaultx'][$i],'',$param)."</span>";
				}
		if($method==0){
			echo $bb;
		}
		if($method==1){
			return $bb;
		}
	}
}

function yinyong($zd,$method=1,$nowvalue,$g='dcfg'){
global $$g;
$temp=$$g;
if($nowvalue!=''){
$tnow=explode(",",$nowvalue);
$str='';
				if($temp['structure'][$zd]['method']['table']!=''){
					if(is_array($tnow)){
						foreach($tnow as $value){
							$tdate=Dga($temp['structure'][$zd]['method']['table']," ".$temp['structure'][$zd]['method']['yvalue']." like '".$value."'");
							$str.=" ".$tdate[$temp['structure'][$zd]['method']['xvalue']];
							//Ja($str);
						}
					}
				}else{
					if(is_array($tnow)){
						foreach($tnow as $value){
							//$tard=array_keys($temp['structure'][$zd]['method']['yvalue'],$value);
							//$str.=" ".$temp['structure'][$zd]['method']['xvalue'][$tard[0]];
							$str.=" ".$temp['structure'][$zd]['method']['xvalue'][$value];
						}
					}
				}
}

		if($method==0){
			echo $str;
		}
		if($method==1){
			return $str;
		}
}
function getparentidsorts($id,$table){
  //取得父分类列表
    global $db,$prefix;
    $sorts=mysql_query("SELECT parentid FROM ".$prefix."_".$table." WHERE id='".$id."'");
    while($sort=mysql_fetch_array($sorts)){
      $id .=",";
      $id .=getparentidsorts($sort[parentid],$table);
    }
    return $id ;
  }

function backdselect($id,$table) {
  //更新父分类列表
    global $db,$prefix;
	$db->query("UPDATE ".$prefix."_".$table." SET plist='".getparentidsorts($id,$table)."'  WHERE id='".$id."'");
  	//echo "UPDATE ".$prefix."_".$table." SET plist='".getparentidsorts($id,$table)."'  WHERE id='".$id."'";
  }

function chazhi($id,$table) {
  //更新父分类列表
    global $db,$prefix;
	$sql="UPDATE ".$prefix."_".$table." SET prc=CEILING( REPLACE(dpr,',',''))-CEILING( REPLACE(zpr,',',''))  WHERE id='".$id."'";
	//echo $sql;
	$db->query($sql);
  	//echo "UPDATE ".$prefix."_".$table." SET plist='".getparentidsorts($id,$table)."'  WHERE id='".$id."'";
  }
/** Dc($table,$zd,$condition='',$type=0)
 *  得到查询语句以$zd为嗾使 一值 的数量
 *
 *
 */
//
function createthumb($src,$otype,$album,$im_des)
{
	if($otype!=".bmp")
	{
	$type=strtolower($otype);
	if($im_des==''){
	$im_des="../../uploads/thumb/".$album.".jpg";
	}
	if($type==".jpg"||$type==".jpeg")
		$im=@imagecreatefromjpeg($src);
	if($type==".gif")
		$im=@imagecreatefromgif($src);
	if($type==".png")
		$im=@imagecreatefrompng($src);
	$width=@imagesx($im);
	$height=@imagesy($im);
	@$ratio=$height/$width;
	if($ratio<0.9)
	{
		$newwidth=135;
		@$newheight=$height*(100/$width);
	}
	else
	{
		$newheight="110";
		$newwidth=$width*(90/$height);
	}
	$im_s=@imagecreatetruecolor($newwidth,$newheight);
	@imagecopyresized($im_s,$im,0,0,0,0,$newwidth,$newheight,$width,$height);
	@imagejpeg($im_s,$im_des,70);
	chmod($im_des,0777);
	@imagedestroy($im);
	}
}

/*
* 功能：PHP图片水印 (水印支持图片或文字)
* 参数：
*      $groundImage    背景图片，即需要加水印的图片，暂只支持GIF,JPG,PNG格式；
*      $waterPos        水印位置，有10种状态，0为随机位置；
*                        1为顶端居左，2为顶端居中，3为顶端居右；
*                        4为中部居左，5为中部居中，6为中部居右；
*                        7为底端居左，8为底端居中，9为底端居右；
*      $waterImage        图片水印，即作为水印的图片，暂只支持GIF,JPG,PNG格式；
*      $waterText        文字水印，即把文字作为为水印，支持ASCII码，不支持中文；
*      $textFont        文字大小，默认为12；以像素为单位
*      $textColor        文字颜色，值为十六进制颜色值，默认为#FF0000(红色)；
*
* 注意：Support GD 2.0，Support FreeType、GIF Read、GIF Create、JPG 、PNG
*      $waterImage 和 $waterText 最好不要同时使用，选其中之一即可，优先使用 $waterImage。
*      当$waterImage有效时，参数$waterString、$stringFont、$stringColor均不生效。
*      加水印后的图片的文件名和 $groundImage 一样。
* 作者：longware @ 2004-11-3 14:15:13
* 修改：Zuolong @ 2010年01月29日 星期五 14时34分54秒 
*       对文字水印的修改。默认字体设定为文泉驿微米黑
*/
function imageWaterMark($groundImage,$waterPos=0,$waterImage="",$waterText="",$textFont=12,$textColor="#FF0000")
{
    $isWaterImage = FALSE;
    $formatMsg = "暂不支持该文件格式，请用图片处理软件将图片转换为GIF、JPG、PNG格式。";
    $font_file=$_SERVER['DOCUMENT_ROOT'].TMPE_PATH."admin/fonts/wqy-microhei-lite.ttc";     //字体路径：文字水印

    //读取水印文件
    if(!empty($waterImage) && file_exists($waterImage))
    {
        $isWaterImage = TRUE;
        $water_info = getimagesize($waterImage);
        $water_w    = $water_info[0];//取得水印图片的宽
        $water_h    = $water_info[1];//取得水印图片的高

        switch($water_info[2])//取得水印图片的格式
        {
            case 1:$water_im = imagecreatefromgif($waterImage);break;
            case 2:$water_im = imagecreatefromjpeg($waterImage);break;
            case 3:$water_im = imagecreatefrompng($waterImage);break;
            default:die($formatMsg);
        }
    }

    //读取背景图片
    if(!empty($groundImage) && file_exists($groundImage))
    {
        $ground_info = getimagesize($groundImage);
        $ground_w    = $ground_info[0];//取得背景图片的宽
        $ground_h    = $ground_info[1];//取得背景图片的高

        switch($ground_info[2])//取得背景图片的格式
        {
            case 1:$ground_im = imagecreatefromgif($groundImage);break;
            case 2:$ground_im = imagecreatefromjpeg($groundImage);break;
            case 3:$ground_im = imagecreatefrompng($groundImage);break;
            default:die($formatMsg);
        }
    }
    else
    {
        Ja("需要加水印的图片不存在！");
    }

    //水印位置
    if($isWaterImage)//图片水印
    {
        $w = $water_w;
        $h = $water_h;
        $label = "图片的";
    }
    else//文字水印
    {
        $temp = imagettfbbox($textFont,0,$font_file,$waterText);//取得使用 TrueType 字体的文本的范围
        $w = $temp[2] - $temp[6];
        $h = $temp[3] - $temp[7];
        unset($temp);
        $label = "文字区域";
    }
    if( ($ground_w<$w) || ($ground_h<$h) )
    {
       ja("需要加水印的图片的长度或宽度比水印".$label."还小，无法生成水印！");
        return;
    }
    switch($waterPos)
    {
        case 0://随机
            $posX = rand(0,($ground_w - $w));
            $posY = rand(0,($ground_h - $h));
            break;
        case 1://1为顶端居左
            $posX = 0;
            $posY = 0;
            break;
        case 2://2为顶端居中
            $posX = ($ground_w - $w) / 2;
            $posY = 0;
            break;
        case 3://3为顶端居右
            $posX = $ground_w - $w;
            $posY = 0;
            break;
        case 4://4为中部居左
            $posX = 0;
            $posY = ($ground_h - $h) / 2;
            break;
        case 5://5为中部居中
            $posX = ($ground_w - $w) / 2;
            $posY = ($ground_h - $h) / 2;
            break;
        case 6://6为中部居右
            $posX = $ground_w - $w;
            $posY = ($ground_h - $h) / 2;
            break;
        case 7://7为底端居左
            $posX = 0;
            $posY = $ground_h - $h;
            break;
        case 8://8为底端居中
            $posX = ($ground_w - $w) / 2;
            $posY = $ground_h - $h;
            break;
        case 9://9为底端居右
            $posX = $ground_w - $w;
            $posY = $ground_h - $h;
            break;
        default://随机
            $posX = rand(0,($ground_w - $w));
            $posY = rand(0,($ground_h - $h));
            break;
    }

    //设定图像的混色模式
    imagealphablending($ground_im, true);

    if($isWaterImage)//图片水印
    {
        imagecopy($ground_im, $water_im, $posX, $posY, 0, 0, $water_w,$water_h);//拷贝水印到目标文件
    }
    else//文字水印
    {
        if( !empty($textColor) && (strlen($textColor)==7) )
        {
            $R = hexdec(substr($textColor,1,2));
            $G = hexdec(substr($textColor,3,2));
            $B = hexdec(substr($textColor,5));
        }
        else
        {
            die("水印文字颜色格式不正确！");
        }
        if(!is_file($font_file)){
            die("水印文字字体不存在！请将字体复制至此：{$font_file}");
        }
        //imagestring ( $ground_im, $textFont, $posX, $posY, $waterText, imagecolorallocate($ground_im, $R, $G, $B));
        imagettftext ( $ground_im, $textFont, 0, $posX, $posY, imagecolorallocate($ground_im, $R, $G, $B), $font_file, $waterText);
    }

    //生成水印后的图片
    @unlink($groundImage);
    switch($ground_info[2])//取得背景图片的格式
    {
        case 1:imagegif($ground_im,$groundImage);break;
        case 2:imagejpeg($ground_im,$groundImage);break;
        case 3:imagepng($ground_im,$groundImage);break;
        default:die($errorMsg);
    }

    //释放内存
    if(isset($water_info)) unset($water_info);
    if(isset($water_im)) imagedestroy($water_im);
    unset($ground_info);
    imagedestroy($ground_im);
}

function Dc($table,$zd,$condition='',$type=0){
	global $db;
	$sql="SELECT DISTINCT (".$zd.") FROM lm_".$table." where 1 ".$condition." ";
if($type==1){
	echo $sql;
	exit;
}
$res=mysql_query($sql);
$temp=mysql_num_rows($res);
return $temp;
}


/**function  Dd($table,$a,$b,$ttttt=0) deletes
 *
 *
 *
 */
function Dd($table,$a,$b,$ttttt=0){global $app;global $prefix;
$app->table = $prefix."_".$table;
$insertSQL = $app->getDeleteSQL($a,$b);
if($ttttt!=0)
{
echo $insertSQL;
exit;
}
$app->query($insertSQL);
//echo $insertSQL;
}

/**function Dga($name,$var,$tttttt=0) fetchaline
 *
 *
 *
 */
function Dga($name,$var,$tttttt=0){
global $prefix;
$sql="SELECT * FROM `".$prefix."_".$name."` WHERE 1 and ".$var.";";
if($tttttt!=0)
{echo $sql;
exit;

}mysql_query("Set Names '".DEFAULT_CHARSET."' ");
$resouce=mysql_query($sql);
if($temp=mysql_fetch_assoc($resouce)){
//echo $temp."is".$temp[0];
return $temp;

}
else
{
return false;
}
}


/**function Dgs($name,$var,$tttttt=0) getsomeinfo
 *
 *
 *
 */
function Dgs($name,$var,$tttttt=0){
global $prefix;
$sql="SELECT * FROM ".$prefix."_".$name." WHERE 1 and ".$var.";";
if($tttttt!=0)
{echo $sql;
exit;
}//echo $sql;
mysql_query("Set Names '".DEFAULT_CHARSET."' ");
$resouce=mysql_query($sql);

$nownum=mysql_num_rows($resouce);
while($temp=mysql_fetch_array($resouce))
{
$temp[znum]=$nownum;
$t[]=$temp;
//print_r($t);
}

if($t){
return $t;
}
else
{
return false;
}
}


/**function  Di ($table,$pairs,$ttttt=0) inserts
 *
 *
 *
 */
function Di($table,$pairs,$ttttt=0){global $app;global $prefix;
$app->table = $prefix."_".$table;
$app->pairs = $pairs ;
$insertSQL = $app->getInsertSQL();//$_POST过来的值名称和数据库字段名对应
if($ttttt!=0)
{
echo $insertSQL;
exit;
}
$app->query($insertSQL);
//echo $insertSQL;
}

/**function  Du ($table,$pairs,$a,$b,$ttttt=0)updates
 *
 *
 *
 */
function Du($table,$pairs,$a,$b,$ttttt=0){global $app;global $prefix;
$app->table = $prefix."_".$table;
$app->pairs = $pairs ;
$insertSQL = $app->getUpdateSQL($a,$b);
if($ttttt!=0)
{
echo $insertSQL;
exit;
}

$app->query($insertSQL);
//echo $insertSQL;
}

/**function Dz($sql) zhisql
 *
 *
 *
 */
function Dz($sql,$ttttt=0){
global $db;mysql_query("Set Names '".DEFAULT_CHARSET."' ");
if($ttttt!=0){
	echo $sql;
	exit;
}
	$result=mysql_query($sql);
	while($temp=mysql_fetch_array($result))
	{
	$tempa[]=$temp;
	}
	mysql_free_result($result);
	return $tempa;
}

/**Epma preg_match_all正则取得数组
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  $out1;
 */
function Epma($str,$pattern){
preg_match_all ($pattern, $str ,$out1,PREG_PATTERN_ORDER);
return $out1;
}

/**RecursiveMkdir($path)
 *Fcd
 */
function Fcd($path){
       if (!file_exists($path))
       {
          Fcd(dirname($path));
           mkdir($path, 0777);
       }
    }

/**function Fl($bodytag,$type='file')getdirinfo返回文件夹下的指定后缀名的文件名或文件夹
 *
 *
 *
 */
function Fl($bodytag,$type='file'){

if( is_dir( $bodytag ) ) {
     if( $handle = opendir( $bodytag ) ) {
         while( false !== ( $file = readdir( $handle ) ) ) {
           # Make sure we don't push parental directories or dotfiles (unix) into the arrays
           if( $file != "." && $file != ".." && $file[0] != "." ) {
               if( is_dir( $bodytag . "/" . $file ) )
                 # Create array for directories
                 $d_arr[$d++] = $file;
               else
                 # Create array for files
                 $f_arr[$f++] = $file;
           }
         }
     }
   }

   # Wrap things up if we're in a directory
   if( is_dir( $handle ) ) closedir( $handle );

   # Sort and reset the arrays
   asort( $d_arr ); reset( $d_arr );//数组升序,再把指针指向数组第一位
   asort( $f_arr ); reset( $f_arr );

   if($type=='dir')
   {
	return  $d_arr;//$type为dir返回文件夹名数组
   }
   else if($type=='file')
   {
   return $f_arr;//$type为file返回文件名称数组
   }
   else
   {
   	 foreach ($f_arr as $value )
	 {
	  if(Sf($type,strtolower($value)))//返回小写文件后缀名是否与$type类型相同,相同则把文件名放入$temp数组中返回
	  {
	  $temp[]=$value;
	  }
	 }
   return $temp;
   }
}

/**writefile($path,$content)
 *Fw
 */
function Fw($path,$content){
   if (!file_exists($path))
   {
       // Call the recursive mkdir function since the "recursive" feature
       // built in to mkdir() is broken.
      Fcd(dirname($path));
			   if (!$fp = @fopen($path, "w+")) {
				   echo "Cannot open file ".$path."";
				   exit;
			   }
			   if (fwrite($fp, $content) === FALSE) {
				   echo "Cannot write to file  ".$path."";
				   exit;
			   }
			   if (!fclose($fp)) {
				   echo "Cannot close file ".$path."";
				   exit;
			   }
   }
   else
   {
		if (!is_writable($path)) {
				   if (!chmod($path, 0775)) {
						 echo "Cannot change the mode of file ".$path."";
						 exit;
				   };
			   }
			   if (!$fp = @fopen($path, "w")) {
				   echo "Cannot open file  ".$path."";
				   exit;
			   }
			   if (fwrite($fp, $content) === FALSE) {
				   echo "Cannot write to file  ".$path."";
				   exit;
			   }
			   if (!fclose($fp)) {
				   echo "Cannot close file  ".$path."";
				   exit;
			   }
   }

}

/**Ja(var $ar);
 * 以 js 方式 即时弹出变量
 */
function Ja($ar,$url=false){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<script language="javascript" charset="utf-8" type="">
alert('<?php echo $ar;?>');
<?php
if($url){
?>
window.location ='<?php echo $url;?>';
<?php
}
?>
</script>
<?PHP
}

/** ce print_r
 *
 *
 *
 */
function Jc($var){ global $_POST ,$_GET,$_FILES,$_SESSION,$_REQUEST,$_SERVER,$_COOKIE,$ttt;

	print("<pre>");
switch ($var)
	{
	  case 'p':
	  	print_r($_POST);
		break;
	  case 'g':
	  	print_r($_GET);
		break;
	  case 'r':
	  	print_r($_REQUEST);
		break;
	  case 's':
	  	print_r($_SESSION);
		break;
	  case 'f':
	  	print_r($_FILES);
		break;
	  case 'c':
	  	print_r($_COOKIE);
		break;
	  case 'e':
	  	print_r($_SERVER);
		break;
	  case 't':
		$ttt->debugging = true;
		break;
	default:
		  	print_r($var);
	}
print("</pre>");
}



/** l lai 来路判断 * global $domain;$webnowml;
 *
 *
 */
function Jl(){
global $domain;$webnowml;
if(eregi($domain,$_SERVER['HTTP_REFERER']))
{
return true;
}
else
{
Jt($webnowml,'非法来路');
}
}


/**_isset($value)判断变量去除左右空格后是否是空值
 *Jp
 */
function Jp($value) {
  if (isset($value) AND trim($value)!="") {
    return true;
  } else {
    return false;
  }
}


/** tiaozhuan//创建下拉列表$name:按钮name的值,$dvalue默认单选按钮的值,$style样式,$js为js样式$value单选按钮值数组
 *
 *
 *
 */

 /*************************************
 *
 *Jt($url,$text,$time,$templates){...}
 *其中增加了一个参数$time,设为几秒钟后跳转
 *2008-8-7 王作龙改
 ***********************************/

 /*************************************
 *
 *Jt($url,$text,$time,$go=0,$templates){...}
 *其中增加了一个参数$go,默认为0,如果为1,则直接跳转,不经过下个页面
 *
 *2008-8-8 王作龙改
 ***********************************/
function Jt($url,$text="",$time="1.5",$go="0",$templates="redirect.htm"){
     global $ttt;
         if (!isset($url)) {
              $url="/index.php";
         }
		 //转换为秒的格式
		 $time*=1000;

		 if($go!="0"){
			echo "<script LANGUAGE=\"Javascript\">";
			echo "window.location= \"$url\" ";
			echo "</script>";
			exit;
		 }
         $ttt->assign('url',$url);
	     $ttt->assign('msg',$text);
		 $ttt->assign('time',$time);
        Ts($templates);
         exit();
}


/** ubb
 *
 *
 *
 */
function Jubb($textname,$info,$rootpath='',$ToolbarSet='0',$ToolbarStartExpanded='true',$skin='default',$language='zh-cn'){
require_once ($rootpath."/includes/ubb/fckeditor.php");
$sBasePath=ROOT_PATH."/includes/ubb/";
$oFCKeditor = new FCKeditor($textname) ;
$oFCKeditor->BasePath	= $sBasePath ;
$oFCKeditor->Height	= "420px";
$oFCKeditor->Config['AutoDetectLanguage']	= false ;
$oFCKeditor->Config['DefaultLanguage']		= $language ;
$ToolbarSet!=0 && $oFCKeditor->ToolbarSet='Basic';
$oFCKeditor->Config['ToolbarStartExpanded']= $ToolbarStartExpanded;
//$skin office2003  silver
$oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/' . htmlspecialchars($skin) . '/' ;
$oFCKeditor->Value		= $info ;
$oFCKeditor->Create() ;
}
function Bubb($textname,$info,$height,$width,$rootpath='',$ToolbarSet='0',$ToolbarStartExpanded='true',$skin='default',$language='zh-cn'){
	//Ja($rootpath."/includes/ubb/fckeditor.php");
	require_once ($rootpath."/includes/ubb/fckeditor.php");
	$sBasePath=ROOT_PATH."/includes/ubb/";


	//Ja($rootpath."/includes/ubb/fckeditor.php");
	$oFCKeditor = new FCKeditor($textname) ;
	$oFCKeditor->BasePath	= $sBasePath ;
	$oFCKeditor->Width	= $width;
	$oFCKeditor->Height	= $height;
	$oFCKeditor->Config['AutoDetectLanguage']	= false ;
	$oFCKeditor->Config['DefaultLanguage']		= $language ;
	$ToolbarSet!=0 && $oFCKeditor->ToolbarSet='Basic';
	$oFCKeditor->Config['ToolbarStartExpanded']= $ToolbarStartExpanded;
	//$skin office2003  silver
	$oFCKeditor->Config['SkinPath'] = $sBasePath . 'editor/skins/' . htmlspecialchars($skin) . '/' ;
		/*
	//表情
	FCKConfig.SmileyPath        = FCKConfig.BasePath + 'images/fun/' ;
	FCKConfig.SmileyImages        = ['m01.gif','m02.gif','m03.gif','m04.gif','m05.gif','m06.gif','m07.gif','m08.gif','m09.gif','m10.gif','m11.gif','m12.gif','m13.gif','m14.gif','m15.gif','m16.gif','m17.gif','m18.gif','m19.gif','m20.gif','m21.gif','m22.gif','m23.gif','m24.gif','m25.gif','m26.gif','m27.gif','m28.gif','m29.gif','m30.gif','m31.gif','m32.gif','m33.gif','m34.gif','m35.gif','m36.gif','m37.gif','m38.gif','m39.gif','m40.gif','m41.gif','m42.gif','m43.gif','m44.gif','m45.gif','m46.gif','m47.gif','m48.gif','m49.gif','m50.gif','m51.gif','m52.gif','m53.gif','m54.gif','m55.gif','m56.gif','m57.gif','m58.gif','m59.gif','m60.gif','m61.gif','m62.gif','m63.gif','m64.gif','m65.gif','m66.gif','m67.gif','m68.gif','m69.gif','m70.gif','m71.gif','m72.gif','m73.gif','m74.gif','m75.gif','m76.gif','m77.gif','m78.gif','m79.gif','m80.gif','m81.gif','m82.gif','m83.gif','m84.gif','m85.gif','m86.gif','m87.gif','m88.gif','m89.gif','m90.gif','m91.gif','m92.gif','m93.gif','m94.gif','m95.gif','m96.gif','m97.gif','m98.gif','m99.gif'] ;
	FCKConfig.SmileyColumns = 8 ;
	FCKConfig.SmileyWindowWidth                = 640 ;
	FCKConfig.SmileyWindowHeight        = 480 ;
	*/
	$oFCKeditor->Value		= $info ;
	$oFCKeditor->Create() ;
}

/**  <br> to \n
 *  * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  return preg_replace( '!<br.*>!iU', "\n", $data );
 */
function Sb2n( $data ) {
   return preg_replace( '!<br.*>!iU', "\n", $data );
}

/**find findme in mystring ($findme,$mystring )in_str
 *
 *
 *
 */
function Sf($findme,$mystring ){
$pos = strpos($mystring, $findme);
if ($pos === false) {
return false;
} else {
 return true;
}
}




/**转换值 <{$smarty.section.li.iteration|tgt:"six":"class='on'"}>
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  array 返回不在 $xian 里出现的新数组
 */
function Tcs($vale,$va2,$va3,$va4=0){
	if($_GET[$va2]==$vale){
		return $va3;
		exit;
	}
	if(!$_GET[$va2]&&$va4!=0){
		return $va3;
		exit;
		}
}

/**chang value ($in,$outta,$out,$order='asc',$jian=0){
 *
 *
 *
 */
function Tcv($in,$outta,$out,$order='asc',$jian=0){
if($jian){
j_a($order);
}
if($order!='asc'&&$order!='desc'){
	if($order='rand()'){
$temp=Dga($outta," bdid='".$in."' order by  ".$order." ");
	}else{
$temp=Dga($outta," ".$order."");
	}
}else{

$temp=Dga($outta," bdid='".$in."' order by ".$out." ".$order."");
}

	if($temp){
	return $temp[$out];
	}
	else{
	return '0';
	}
}

/**cvts($in,$outta,$out,$order='asc',$limit=''){
 *
 *
 *
 */
function Tcvs($in,$outta,$out,$order='asc',$limit=''){
$temp=Dgs($outta," bdid='".$in."' order by ".$out." ".$order." ".$limit." ");
	if($temp){
	return $temp;}
	else{
	$temp[0][znum]=0;
	return $temp;
	}
}
//转换同一表里的key value
function Tzh($in,$table,$zd,$czd){
$temp=Dga($table," ".$zd."='".$in."' ");
	return $temp[$czd];
}

/**   date 原型  老是感觉 smarty的date_format太不好用 t 模版  d 时间 <{$content[li].e|t_d:"Y-m-d H:i:s"}>
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return date($xing,$qian)
 */
function Td($qian=0,$xing){
if($qian==0){
 return  date($xing);
}else{
 return  date($xing,$qian);
}
}


/**time jian ge  转换时间签为时间间隔
 *
 *
 *
 */
function Tjg ($timeq,$type,$nowtime=0){
if($nowtime==0){
	$nowtime=time();
}
$cha=$nowtime-$timeq;
	if($type=='d'){
	return floor($cha/(3600*24));
	}
	if($type=='h'){
	return floor($cha/3600);
	}
	if($type=='m'){
	return floor($cha/60);
	}
	if($type=='h-m'){
		$temp[h]=floor($cha/3600);
		$temp[m]=floor(($cha-3600*(floor($cha/3600)))/60);
	return $temp;
	}
	if($type=='d-h'){
		$temp[d]=floor($cha/(3600*24));
		$temp[h]=floor(($cha-3600*24*(floor($cha/(3600*24))))/3600);
	return $temp;
	}
	if($type=='d-h-m'){
		$temp[d]=floor($cha/(3600*24));
		$temp[h]=floor(($cha-3600*24*(floor($cha/(3600*24))))/3600);
		$temp[m]=floor(($cha-$temp[d]*3600*24-$temp[h]*3600)/60);
	return $temp;
	}
}


/**tkv 转换数据的key value{
 *
 *
 *
 */
function Tkv ($key,$wz){
global $$wz;
return ${$wz}[$key];
}


function Tr($value,$tmpname){
global $ttt;
$ttt->assign($tmpname,$value);
}
/**assignone($tmpname,$datebae,$condition,$field=1,$show=0)
 *Ta
 */
function Tra($tmpname,$datebae,$condition,$field=1,$show=0){ global $ttt;

if($show!=0)
{
$temp=Dga($datebae,$condition,1);
}
else
{
$temp=Dga($datebae,$condition);
}
	if($field==1)
	{
		if($temp[content]!='')
		{
			$temp[content]=stripslashes($temp[content]);
		}
	$ttt->assign($tmpname,$temp);
	}
	else
	{
	$ttt->assign($tmpname,stripslashes($temp[$field]));
	}
	return $temp;
}


function Trf($tmpname,$mbmlu){
global $ttt;
$contents=$ttt->fetch($mbmlu);
$ttt->assign($tmpname,$contents);
}

/**assignlist 返回不在 $xian 里出现的新数组
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return  array 返回不在 $xian 里出现的新数组
 */
function Trl($table,$condition='order by id desc',$dateval='',$mdateval='',$getvale='',$assiname='content',$pageline=15,$n=5,$type=2,$pagenamese='page',$navname='nav',$tttt=0){
//print_r($condition);
global $ttt,$_GET,$_POST,$db,$prefix;
//echo '5555555555555555'.$navname;
//print_r($_GET);
$temp=explode("#",$getvale);
$i=0;
$j=count($temp);

if(!isset($_GET[$pagenamese])){
$_GET[$pagenamese]=1;
}
if(isset($_POST[$pagenamese])){
$_GET[$pagenamese]=$_POST[$pagenamese];
}
	if($getvale!='')
	{
	foreach($temp as $value)
	{
	($_GET[$value]=='' && ( $value=='pic' || $value=='pinglunpg' ))?$_GET[$value]=1:'';
		if($i<$j)
		 {		$action.=$value."=".$_GET[$value]."&";

		 }
		 else
		 {
		$action.=$value."=".$_GET[$value];
		 }
	 $i++;
	}
	}




	$temp='';
	//print_r($temp);
	if($mdateval!='')
	{
		$temp=explode("#",$mdateval);
	foreach($temp as $value)
	{
	($_GET[$value]=='' && ( $value=='pic' || $value=='pinglunpg' ))?$_GET[$value]=1:'';
	$condition=" and  ".$value." like '%".$_GET[$value]."%' ".$condition;
	$action.="&".$value."=".$_GET[$value]."";
	}
	}



	$temp='';
	if($dateval!='')
	{
	$temp=explode("#",$dateval);
	foreach($temp as $value)
	{
	($_GET[$value]=='' && ( $value=='pic' || $value=='pinglunpg' ))?$_GET[$value]=1:'';
	$condition=" and  ".$value." like '".$_GET[$value]."' ".$condition;
	$action.="&".$value."=".$_GET[$value]."";
	}
    }

$sql="select count(id) as num from ".$prefix."_".$table." where 1 ".$condition." ;";
$res=mysql_query($sql);
$temp=mysql_fetch_array($res);
$pagelist=$_GET[$pagenamese].",".$n.",".$pageline.",".$temp[num].",'".$action."',".$type.",'','".$pagenamese."'";
//echo($pagelist);
//echo $navname;
shownav($pagelist,$navname);
//echo '5555555555555555555555555555555555555555'.$_GET[$pagenamese];
if($tttt!=0){
$res=Dgs($table," 1   ".$condition."  LIMIT ".($_GET[$pagenamese]-1)*$pageline." , ".$pageline."");
}
$res=Dgs($table," 1   ".$condition."  LIMIT ".($_GET[$pagenamese]-1)*$pageline." , ".$pageline."");
	if($table=='cp')
	{
		 	foreach($res as $key =>$value)
				{
				$res[$key][content]=html_entity_decode($res[$key][content]);

				}

	}
$ttt->assign($assiname,$res);
return $res;
}


function  Trs($tmpname,$datebae,$condition,$field=0,$show=0){
global $ttt;
if($show!=0)
{
$temp=Dgs($datebae,$condition,1);
}
else
{
$temp=Dgs($datebae,$condition);
}
		if($field)
		{
			$tfield=explode("#",$field);

			 	foreach($temp as $key =>$value)
				{
					 foreach($tfield as $tvalue)
						 {
					$temp1[$key][$tvalue]=html_entity_decode($temp[$key][$tvalue]);
						//Ja(	$temp[$key][$tvalue]);
						}
				}

	 $ttt->assign($tmpname,$temp1);
	return $temp1;

		}else{
	$ttt->assign($tmpname,$temp);
return $temp;

	}

}

/**show  显示
 * @param template  模版名字
 * @param type   0  no exit;   1 exit
 * @return true
 */
function Ts($template,$type=0){
  global $ttt;
  $ttt->display($template);
  if($type ==1){
  exit;
  }
}


/**  yin(隐 set 不显示的条件
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return date($xing,$qian)
 */
function Ty($a,$b){
if ($a==$b){
return NULL;
}
else{
return $a;
}
}
/**  Mct 当前时间加微秒×100
 * @param unknown_type $ar
 * @xian str   0 返回不重复数组   1 返回不重复并且不为空
 * @return date($xing,$qian)
 */
function Mct()
{
    list($usec, $sec) = explode(" ", microtime());
    return 100*(((float)$usec + (float)$sec));
}
/**  Bic 当前时间加微秒×100+3组随机数相乘
 *
 * @Author by ZuoLong
 */
function Bic()
{
    list($usec, $sec) = explode(" ", microtime());
	$usec=$usec+(rand(1,400)*rand(400,900)*rand(900,1300));
	$sec=$sec+(rand(1,400)*rand(400,900)*rand(900,1300));
    return 100*(((float)$usec + (float)$sec));
}
function getip()
{
  if (getenv("HTTP_CLIENT_IP") && strcasecmp(getenv("HTTP_CLIENT_IP"), "unknown"))
          $ip = getenv("HTTP_CLIENT_IP");
      else if (getenv("HTTP_X_FORWARDED_FOR") && strcasecmp(getenv("HTTP_X_FORWARDED_FOR"), "unknown"))
          $ip = getenv("HTTP_X_FORWARDED_FOR");
      else if (getenv("REMOTE_ADDR") && strcasecmp(getenv("REMOTE_ADDR"), "unknown"))
          $ip = getenv("REMOTE_ADDR");
      else if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] && strcasecmp($_SERVER['REMOTE_ADDR'], "unknown"))
          $ip = $_SERVER['REMOTE_ADDR'];
      else
          $ip = "unknown";
  return($ip);
}
function filtip($ip){
	//select "." left place  in id
		//exg.  192.168.1.1  return 10;
	(trim($ip)=='')?$ip='unknown':'';
	//如果IP中有'.'才进行里面的操作
	if(strstr($ip,'.')!=''){
		$ipdow=strrpos($ip,'.')+1;
		$leftip=substr($ip,0,$ipdow);
		$leftip='IP:'.$leftip.'*';
	}else{$leftip='IP:unknown';}
	return $leftip;
}
function atoh($ar){
	$str='';
	foreach($ar as $key =>$value){
	$str.="<input type=\"hidden\" name=\"".$key."\"  id='".$key."' value=\"".$value."\">";
	}
	return $str;
}
function Sidtitle($id,$zd='title',$table='sort'){
	$temp=Dga($table," id = '".$id."'");
	if($zd==''){
		return $temp;
	}else{
		return $temp[$zd];
	}
}
/************************************
*
*检测图片是否存在
*	$filename-图片文件名;
*	$nopic-没有图片时的图片名,默认为 ***.***;
*	$picroot设定上传的图片的路径,也就是 '无此图'  的图片所在的目录
*
************************************/
function getpic($filename,$nopic='nofind.jpg',$picroot=0,$thumb=0,$setUrl = 'http://www.ziyou.com.cn'){
	//设定上传的图片的路径,也就是 '无此图'  的图片所在的目录
		//此处可手动设置图片目录
	($picroot==0)?$picroot='/uploads/pic/':'';

	$tmp=$nopic;
	global $nopic;
	($nopic=='')?$nopic=$tmp:'';
	if($thumb==0){
		$filepath = $_SERVER[DOCUMENT_ROOT].$picroot;	//set the picture saved path
	}else{
		$filepath = '../../uploads/thumb/';	//set the picture saved thumb
	}
	//文件名为空 则直接返回     '无此图'   的图片
	if($filename==''){
		$filename1 = $filepath.$nopic;
		//将文件名 设定为 $nopic
		$filename  = $nopic;
	}else{
		$filename1 = $filepath.$filename;
	}
	if (file_exists($filename1)) {
		$getValue = $picroot.$filename;
	} else {
		//$getValue = $setUrl."/uploads/pic/".$filename;	//这是原来 的代码 ,做个备份
		$getValue = $picroot.$nopic;
	}
	//如果本站没有 '无此图'  的图片,将从其他站中载入 ---$setUrl
	if (file_exists($filepath.$getValue)){
		$getValue = $setUrl.$picroot.$nopic;
	}
	return $getValue;
}

/**
 * *******************
 * 去除所有的html标签
 */
function clearhtml( $str ){
	 $strtemp = trim($str);
	 $search  = array(
	 "|'|Uis",
	 "|<script[^>]*?>.*?</script>|Uis",  // 去掉 javascript
	 "|<[\/\!]*?[^<>]*?>|Uis",    // 去掉 HTML 标记
	 "'&(quot|#34);'i",      // 替换 HTML 实体
	 "'&(amp|#38);'i",
	 "|,|Uis",
	 "|[\s]{2,}|is",
	 "[&nbsp;]isu",
	 "|[$]|Uis",
	 );
	 $replace = array(
	 "`",
	 "",
	 "",
	 "",
	 "",
	 "",
	 " ",
	 " ",
	 " dollar ",
	 );
	 $text = preg_replace($search, $replace, $strtemp);
	 return $text;
}
/*
*php实现escape,unescape解码
*@Author by 赵宪楠
*/
function unescape($str)
	{
        $str = rawurldecode($str);
        preg_match_all("/(?:%u.{4})|.+/",$str,$r);
        $ar = $r[0];
         foreach($ar as $k=>$v)
		 {
             if(substr($v,0,2) == "%u" && strlen($v) == 6)
			 {
                $ar[$k] = iconv("UCS-2","GB2312",pack("H4",substr($v,-4)));
             }
         }
         return join("",$ar);
     }

function escape($str) {
        preg_match_all("/[\x80-\xff].|[\x01-\x7f]+/",$str,$r);
        $ar = $r[0];
         foreach($ar as $k=>$v) {
             if(ord($v[0]) < 128) {
                $ar[$k] = rawurlencode($v);
             } else {
                $ar[$k] = "%u".bin2hex(iconv("GB2312","UCS-2",$v));
             }
         }
         return join("",$ar);
     }

/**
 * *********************
 * 补充系统没有json的函数
 */
if ( !function_exists('json_decode') ){
    function json_decode($content, $assoc=false){
                require_once (dirname(__FILE__).'/JSON.php');
                //Jc(dirname(__FILE__).'/JSON.php');
                if ( $assoc ){
                    $json = new Services_JSON(SERVICES_JSON_LOOSE_TYPE);
        } else {
                    $json = new Services_JSON;
                }
        return $json->decode($content);
    }
}

if ( !function_exists('json_encode') ){
    function json_encode($content){
                require_once (dirname(__FILE__).'/JSON.php');
                $json = new Services_JSON;

        return $json->encode($content);
    }
}



// 说明：Utf-8、gb2312都支持的汉字截取函数
// 整理：http://www.CodeBit.cn

/*
Utf-8、gb2312都支持的汉字截取函数
cut_str(字符串, 截取长度, 开始长度, 编码);
编码默认为 utf-8
开始长度默认为 0
*/

function cutstr($string, $sublen, $start = 0, $code = 'UTF-8')
{
    if($code == 'UTF-8')
    {
        $pa = "/[\x01-\x7f]|[\xc2-\xdf][\x80-\xbf]|\xe0[\xa0-\xbf][\x80-\xbf]|[\xe1-\xef][\x80-\xbf][\x80-\xbf]|\xf0[\x90-\xbf][\x80-\xbf][\x80-\xbf]|[\xf1-\xf7][\x80-\xbf][\x80-\xbf][\x80-\xbf]/";
        preg_match_all($pa, $string, $t_string);

        if(count($t_string[0]) - $start > $sublen) return join('', array_slice($t_string[0], $start, $sublen))."...";
        return join('', array_slice($t_string[0], $start, $sublen));
    }
    else
    {
        $start = $start*2;
        $sublen = $sublen*2;
        $strlen = strlen($string);
        $tmpstr = '';

        for($i=0; $i<$strlen; $i++)
        {
            if($i>=$start && $i<($start+$sublen))
            {
                if(ord(substr($string, $i, 1))>129)
                {
                    $tmpstr.= substr($string, $i, 2);
                }
                else
                {
                    $tmpstr.= substr($string, $i, 1);
                }
            }
            if(ord(substr($string, $i, 1))>129) $i++;
        }
        if(strlen($tmpstr)<$strlen ) $tmpstr.= "...";
        return $tmpstr;
    }
}

// 说明：获取 _SERVER['REQUEST_URI'] 值的通用解决方案
// 来源：drupal-5.1 bootstrap.inc
// 整理：CodeBit.cn ( http://www.CodeBit.cn )

function request_uri()
{
    if (isset($_SERVER['REQUEST_URI']))
    {
        $uri = $_SERVER['REQUEST_URI'];
    }
    else
    {
        if (isset($_SERVER['argv']))
        {
            $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['argv'][0];
        }
        else
        {
            $uri = $_SERVER['PHP_SELF'] .'?'. $_SERVER['QUERY_STRING'];
        }
    }
    return $uri;
}
/*******************
* 搜索/添加 http://
*/
function check_url($url,$prefix='http://',$suffix='.com'){
	if(strrpos($url,$prefix) === false) {
		if(strrpos($url,'.') === false) {
			$newUrl=$prefix.$url.$suffix;
		}else{
			$newUrl=$prefix.$url;
		}
	}
	return $newUrl;
}

/**
 * 计算日期差
 *  写了一个5.3新增的函数 date_diff。现更名 为date_diff_bic
 *
 * @param string time $date1	Y-m-d H:i:s
 * @param string time $date2	Y-m-d H:i:s
 * @param string $return_type
 * 		返回类型:'s'-秒	'i'-分	'h'-小时		'd'-天	'w'-星期		'm'-月	'y'-年
 * 		默认:'d'-天
 * @param bool $ceil
 * 		是否四舍五入
 * 		默认:false
 * @return numeric
 * @author Bic
 * 		2009年9月26日 10时28分46秒
 * 		2010年6月9日   修改函数名
 */
function date_diff_bic($date1, $date2, $return_type='d',$ceil=false) {
    $timestamp1 = is_numeric($date1)?$date1:strtotime($date1);
    $timestamp2 = is_numeric($date2)?$date2:strtotime($date2);
    switch ($return_type){
        case 's':
        case 'second':
            $result = ($timestamp2-$timestamp1);
            break;
        case 'i':
        case 'minute':
            $result = ($timestamp2-$timestamp1)/60;
            break;
        case 'h':
        case 'hour':
            $result = ($timestamp2-$timestamp1)/3600;
            break;
        case 'd':
        case 'day':
            $result = ($timestamp2-$timestamp1)/86400;
            break;
        case 'w':
        case 'week':
            $result = ($timestamp2-$timestamp1)/604800;
            break;
        case 'm':
        case 'month':
            $result = ($timestamp2-$timestamp1)/2592000;
            break;
        case 'y':
        case 'year':
            $result = ($timestamp2-$timestamp1)/946080000;
            break;
    }
    return $ceil?ceil($result):floor($result);
}

/********************
 * 后台新数据配置插件用
 * d2t:date转为time时间戳
 * Author by Bic.
 */
function d2t($A){
	return strtotime($A);
}


/**
 * // 说明：PHP中二维数组的排序方法
 * // 整理：http://www.CodeBit.cn
 * @package     BugFree
 * @version     $Id: FunctionsMain.inc.php,v 1.32 2005/09/24 11:38:37 wwccss Exp $
 *
 *
 * Sort an two-dimension array by some level two items use array_multisort() function.
 *
 * sysSortArray($Array,"Key1","SORT_ASC","SORT_RETULAR","Key2"……)
 * @author                      Chunsheng Wang <wwccss@263.net>
 * @param  array   $ArrayData   the array to sort.
 * @param  string  $KeyName1    the first item to sort by.
 * @param  string  $SortOrder1  the order to sort by("SORT_ASC"|"SORT_DESC")
 * @param  string  $SortType1   the sort type("SORT_REGULAR"|"SORT_NUMERIC"|"SORT_STRING")
 * @return array                sorted array.
 */
function sysSortArray($ArrayData,$KeyName1,$SortOrder1 = "SORT_ASC",$SortType1 = "SORT_REGULAR")
{
    if(!is_array($ArrayData))
    {
        return $ArrayData;
    }

    // Get args number.
    $ArgCount = func_num_args();

    // Get keys to sort by and put them to SortRule array.
    for($I = 1;$I < $ArgCount;$I ++)
    {
        $Arg = func_get_arg($I);
        if(!eregi("SORT",$Arg))
        {
            $KeyNameList[] = $Arg;
            $SortRule[]    = '$'.$Arg;
        }
        else
        {
            $SortRule[]    = $Arg;
        }
    }

    // Get the values according to the keys and put them to array.
    foreach($ArrayData AS $Key => $Info)
    {
        foreach($KeyNameList AS $KeyName)
        {
            ${$KeyName}[$Key] = $Info[$KeyName];
        }
    }

    // Create the eval string and eval it.
    $EvalString = 'array_multisort('.join(",",$SortRule).',$ArrayData);';
    eval ($EvalString);
    return $ArrayData;
}

/********************
* 加密!

* 很乱的 一个加密
* Author by Bic.
*/
function JM($validate){
	for($i=1;$i<13;$i++){
		if($i<5){
			//$validate=$i%2==0?md5($validate):'';
			$validate=md5($validate);
		}else{
			//$validate=$i%2==0?$validate=sha1($validate):'';
			$validate=sha1($validate);
		}
	}
	return md5($validate);
}




/********************************
*
*	网站私有,可随时删除
*
*&*&***************************.*/
/*
* 查找模块配置文件中的信息
* By Bic 2009-3-4
*/
function dcfg($arr){
	if(is_array($arr)){
		if($arr['getid']!=''){
			$dg='"name":"'.$arr['getid'].'","';
			$t=Dga('dcfg',"dcfg like '%".$dg."%'");
			return $t['id'];
		}
		if($arr['getname']!=''){
			$t=Dga('dcfg',"id='".$arr['getname']."'");
			$x=json_decode($t['dcfg']);
			return $x->name;
		}
	}else{
		if(is_numeric($arr)){
			$t=Dga('dcfg',"id='".$arr."'");
			$x=json_decode($t['dcfg']);
			return $x->name;
		}else{
			$dg='"name":"'.$arr.'","';
			$t=Dga('dcfg',"dcfg like '%".$dg."%'");
			return $t['id'];
		}

	}

}

/*
* 根据当前数据的bdb,bdid返回其父数据的id
* By Bic 2009年9月15日 11时12分05秒
*/
function get_parent_id($bdb,$bdid,$lg='zh'){
	$t=Dga('dcfg',"id={$bdb}");
	$x=json_decode($t['dcfg']);
	$table=$x->name;
	$info=Dga($table,"del!=1 and gid like '{$bdid}' and lg like '{$lg}'");
	return $info['id'];
}

/**
 * 根据当前数据的bdb,bdid返回其父数据信息
 * @param $bdb	父级表
 * @param $bdid	父级gid
 * @param $field要返回的字段。默认：id
 * @param $lg	父级语言。默认：zh
 * @return string | int
 * @author Bic 2010年5月26日 10时54分41秒
 */
function get_parent_info($bdb,$bdid,$field='id',$lg='zh'){
	$t=Dga('dcfg',"id={$bdb}");
	$x=json_decode($t['dcfg']);
	$table=$x->name;
	$info=Dga($table,"del!=1 and gid like '{$bdid}' and lg like '{$lg}'");
	return $info[$field];
}

/*
 * 获取固定的select,radio,checkbox的值对
 */
function get_value_dcfg_arr($arr){
    if ($arr['sortid']!=''){
		$t=Dga('dcfg',"id={$arr['sortid']}");
		$x=json_decode($t['dcfg']);
    }else if ($arr['sortname']!=''){
        $dg='"name":"'.$arr.'","';
		$t=Dga('dcfg',"dcfg like '%".$dg."%'");
		$x=json_decode($t['dcfg']);
    }
    $new = array();
    foreach ($x->structure->$arr['field']->method->yvalue as $k=>$v){
        $new[$v] = $x->structure->$arr['field']->method->yvalue[$k];
    }
    if ($arr['key']!=''){
        $new = $new[$arr['key']];
    }
    return $new;
}
function get_value_dcfg($sortid,$field,$key){
	$t=Dga('dcfg',"id={$sortid}");
	$x=json_decode($t['dcfg']);

    $new = array();
    foreach ($x->structure->$field->method->yvalue as $k=>$v){
        $new[$v] = $x->structure->$field->method->yvalue[$k];
    }
    if ($key!=''){
        $new = $new[$key];
    }
    return $new;
}

//获取等级
function getlevel($userid,$type=0,$default='小兵'){
	$uinfo=Dz("select integral,userid,renzheng from lm_member where 1 and userid like '".$userid."'");
	if($uinfo[0]['renzheng']!=0){
		$levelInfo=Dga('level',"del!=1 and start <= ".$uinfo[0]['integral']." and end > ".$uinfo[0]['integral']."");
		if($type==0){
			return $levelInfo['title']==''?$default:$levelInfo['title'];
		}else{
			return $levelInfo['level']==''?'1':$levelInfo['level'];
		}
	}else{
		if($type==0){
			return '未认证';
		}else{
			return 1;
		}
	}
}
//获取用户信息
function getuinfo($arr){
	$uinfo=Dga('member',"del!=1 and userid like '".$arr['userid']."'");
	if($arr['return']=='*'){
		return $uinfo;
	}else {
		return $uinfo[$arr['return']];
	}
}

function keygen($max){

	$items = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*,./?'\"(){}";
	$x = 1;
	$total = strlen($items) - 1;

	while($x <= $max){

	$rand = rand(0, $total);

	$item = substr($items, $rand, 1);
	if($x == 1){
		$key = $item;
	}
	elseif($x > 1)
	{
		$key .= $item;
	}
		$x++;
	}

	return $key;
}
/*******************************
* arr2str
*   数组转换为可视化/可操作性 字符串
*   for cms 数据配置
*   9:14 2009年4月10日星期五
*********************************/
function arr2str($post_info,$step=1){
	if ($step==1) {
		ob_start();
	}
	$z=1;
	$n=count($post_info);
	print_r( $step==1?"<?php\n\$tjson=":'');
	print_r( "array(\n");
	foreach($post_info as $k => $v){
		for($y=1;$y<=$step;$y++){
			print_r( "\t");
		}
		print_r( "'".$k."'=>");
		if(is_array($v)){
			arr2str($v,$step+1);

					/*判断是否为数组的最后一个元素*/
		if($z==$n){
			print_r( "\n");
		}else{
			print_r( ",\n");
		}

		}else{
			echo $z<=$n?"'":'';
			print_r( "".$v);
			echo $z==$n?"'":'';
					/*判断是否为数组的最后一个元素*/
		if($z==$n){
			print_r( "\n");
		}else{
			print_r( "',\n");
		}
		}



		$z++;
	}
	for($y=1;$y<=$step;$y++){
		print_r( "\t");
	}
	print_r( ')');
	/*判断是否为数组的最后一个元素*/
	if($z<$n){
		print_r( ',');
	}
	if ($step==1) {
		echo "\n?>";
		$return=ob_get_contents();
		ob_end_clean();
		return $return;
	}


}
/*
*esub截取字符转至帝国
*
*@Author by 赵宪楠
*/
//截字函数
function sub($string,$start=0,$length,$mode=false,$dot=''){
	$dao_charver='utf-8';
	if(empty($length))
	{
		return $string;
	}
	$strlen=strlen($string);
	if($strlen<=$length)
	{
		return $string;
	}

	$string = str_replace(array('&nbsp;','&amp;','&quot;','&lt;','&gt;','&#039;'), array(' ','&','"','<','>',"'"), $string);

	$strcut = '';
	if(strtolower($dao_charver) == 'utf-8') {

		$n = $tn = $noc = 0;
		while($n < $strlen) {

			$t = ord($string[$n]);
			if($t == 9 || $t == 10 || (32 <= $t && $t <= 126)) {
				$tn = 1; $n++; $noc++;
			} elseif(194 <= $t && $t <= 223) {
				$tn = 2; $n += 2; $noc += 2;
			} elseif(224 <= $t && $t < 239) {
				$tn = 3; $n += 3; $noc += 2;
			} elseif(240 <= $t && $t <= 247) {
				$tn = 4; $n += 4; $noc += 2;
			} elseif(248 <= $t && $t <= 251) {
				$tn = 5; $n += 5; $noc += 2;
			} elseif($t == 252 || $t == 253) {
				$tn = 6; $n += 6; $noc += 2;
			} else {
				$n++;
			}

			if($noc >= $length) {
				break;
			}

		}
		if($noc > $length) {
			$n -= $tn;
		}

		$strcut = substr($string, 0, $n);

	} else {
		for($i = 0; $i < $length; $i++) {
			$strcut .= ord($string[$i]) > 127 ? $string[$i].$string[++$i] : $string[$i];
		}
	}

	$strcut = str_replace(array('&','"','<','>',"'"), array('&amp;','&quot;','&lt;','&gt;','&#039;'), $strcut);

	return $strcut.$dot;
}

//截取字数
function esub($string,$length,$dot=''){
	if(empty($length))
	{
		return $string;
	}
	return sub($string,0,$length,false,$dot);
}
/*
*
*转换url编码将utf-8转为gb2312实现其它搜索引擎调用
*
*@Author by 赵宪楠
*/
function str_encode($str)
{
            $str=iconv('UTF-8','GB2312',$str);
                $str=urlencode($str);
                $str=str_replace('+','%20',$str);
                return  $str;
}
/*
*
*将序列化转换为数组
*un_val('模板标签','infosort','id','字段');
*@Author by 赵宪楠
*/

function un_val($tmpname,$table,$tid,$zd,$type)
{
	global $ttt;
	if($type==1) $tmp_type=$type;
	$t1=Dz("select ".$zd." from lm_".$table." where id='".$tid."'",$tmp_type);
	$t2=unserialize($t1[0][$zd]);
	$t3=explode("#",$t2[value]);
		foreach($t3 as $vlue)
		{
			$t4[]=explode('-',$vlue);
		}
	if($type==2) Jc($t4);
	$ttt->assign($tmpname,$t4);
	$ttt->assign(t_num,count($t4));
	return $t4;


}

/**
 * page_s 分页函数
 *
 * lm_page 分页封装
 * 以分页类lm_page为基础,封装的函数.
 *
 * page_b($result='result',$table,$condition,$perpage=8,$type=1,$nav='nav',$page_name='page')
 * @author                      Bic	2009年6月27日
 * @param  string  $result		数据结果的模板变量
 * @param  string  $table		表名
 * @param  string  $condition	条件
 * @param  string  $perpage		一页显示几条	默认8条
 * @param  string  $type		分页类型		默认1
 * @param  string  $nav			分页模板变量	默认'nav'
 * @param  string  $page_name	地址栏显示的分页名	默认'page'
 * @return array                array.
 */
function page_s($result='result',$table,$condition,$perpage=8,$type=1,$nav='nav',$page_name='page'){
	//配置搜索
	!$condition && $condition=1;
	!$result && $result='result';
	!$nav && $nav='nav';
	$sql = "SELECT count(id) as num
		FROM lm_{$table}
		where 1  and del!=1  and ".$condition;
	$res = mysql_query($sql);

	$num_row = mysql_num_rows($res);
	if(strrpos($condition,'group by')!==false){
		$temp['num'] = $num_row;
	}else{
		$temp = mysql_fetch_array($res);
	}
	//每页
	$perpage = $perpage;
	!$_GET[$page_name] && $_GET[$page_name] = 1;
	$ajaxpage = new lm_page( array ('total'=>$temp[num], 'perpage'=>$perpage,'page_name'=>$page_name));
	mysql_free_result($res);
	Tr($ajaxpage->show($type),$nav);

	$R=Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage);
	Tr($R,$result);
	return $result;
}
//同上,只是这个的参数为数组
function page_a(
			$param=array(
				'result'	=>'result',
				'table'		=>'',
				'condition'	=>'',
				'perpage'	=>8,
				'type'		=>1,
				'nav'		=>'nav',
				'pagename'	=>'page',
				'debug'
				)
)
{
	$result		=	$param['result']==''?'result':$param['result'];
	$table		=	$param['table'];
	$condition	=	$param['condition'];
	$perpage	=	$param['perpage']==''?8:$param['perpage'];
	$type		=	$param['type']==''?1:$param['type'];
	$nav		=	$param['nav']==''?'nav':$param['nav'];
	$page_name	=	$param['page_name']==''?'page':$param['page_name'];

	//配置搜索
	!$condition && $condition=1;
	!$result && $result='result';
	!$nav && $nav='nav';
	$sql = "SELECT count(id) as num
		FROM lm_{$table}
		where 1  and del!=1  and ".$condition;
	$res = mysql_query($sql);

	$num_row = mysql_num_rows($res);
	if(strrpos($condition,'group by')!==false){
		$temp['num'] = $num_row;
	}else{
		$temp = mysql_fetch_array($res);
	}
	//每页
	$perpage = $perpage;
	!$_GET[$page_name] && $_GET[$page_name] = 1;
	$ajaxpage = new lm_page( array ('total'=>$temp[num], 'perpage'=>$perpage,'page_name'=>$page_name));
	mysql_free_result($res);
	Tr($ajaxpage->show($type),$nav);

	if($param['debug']!=''){

		Jc('<b>SQL:</b><br />');
		Jc("SELECT * FROM lm_{$table} WHERE 1 AND del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage);

		Jc('<b>Result:</b><br />');
		Jc(Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage));

		Jc('<b>SQL:</b><br />');
		Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage,1);
	}
	$R=Dgs($table,"del!=1 and {$condition} limit ".($_GET[$page_name]-1)*$perpage.",".$perpage.$debug);
	Tr($R,$result);
	return $R;
}

/**
 * 写入网站日志
 *
 * @param string $user	后台用户
 * @param string $info	log内容
 */
function write_log($user,$info,$debug=0){
    defined('LOG_OPEN') || define('LOG_OPEN',true);
    $n['user'] = $user;
    $n['info'] = $info;
    $n['addtime'] = time();
    $n['gid'] = Bic();
    $n['ip'] = getip();
    if (LOG_OPEN){
        if($debug!=0){
            Di('log',$n,1);
        }else{
            Di('log',$n);
        }
    }
}

/**
 *网站配置
 * 其实就是获取表lm_config信息
 * 功能：拥有缓存功能
 * @staticvar array|string $config  静态缓存变量。只在当前脚本有用
 * @param int $sortid   模块id
 * @param string $field 返回字段
 * @param string $table 搜索表。默认为lm_config表
 * @return string
 */
function get_config($sortid,$field="title",$table='config'){
    global $lang;
    static $config;
    if($config[$sortid]==''){
        $config[$sortid]=Dga($table,"del!=1 {$lang} and sortid={$sortid} order by addtime desc");
    }
    return $config[$sortid][$field];
}


/**
 *获取url参数
 *  带有过滤垃圾参数的功能
 *  usage:
 *  	当前页面地址为http://www.example.com/index.php?param1=1&param2=2
 *  	调用get_url_parameter()将返回:param1=1&param2=2
 * @param string $order 过滤选项，多个用","号分隔
 * @param string $arr 要处理的数组，默认为$_GET
 * @param string $arr_key 递归调用参数[不了解，最好默认！不填写！]
 * @return string
 */
function get_url_parameter($order,$arr,$arr_key=NULL){
    $url='';
    $fields=explode(',',$order);
    $arr || $arr=$_GET;
    foreach ($arr as $get_key=>$get_val){
        /**
         * uri 里面含有数组
         * 	用了递归的处理方法
         */
        if(is_array($get_val)){
            $t = get_url_parameter('',$get_val,$get_key);
            
            if($url==''){
                $url=$t;
            }else{
                $url.="&{$t}";
            }
            continue;
        }
        
        if ($arr_key){
            /**
             * 递归调用进入此处理
             */
            if($url==''){
                $url.=$arr_key."[$get_key]={$get_val}";
            }else{
                $url.="&$arr_key"."[$get_key]={$get_val}";
            }
            
        }else{
            if(array_search($get_key,$fields)!==false){
                continue;
            }
            
            if($url==''){
                $url.="{$get_key}={$get_val}";
            }else{
                $url.="&{$get_key}={$get_val}";
            }
        }
    }
    return $url;
}



